package com.springboot.web.serializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.springboot.web.entity.Rating;

import java.io.IOException;

public class RatingDeserializer extends JsonDeserializer<Rating> {
    @Override
    public Rating deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        String ratingValue = p.getText(); // 获取 JSON 中的字符串值
        return Rating.fromName(ratingValue); // 调用 Rating 枚举的解析方法
    }
}